package com.example.leetcode.leetcode.hot100;

import java.util.Arrays;

/**
 * @author haitao
 * <p>
 * 双指针（颜色分类）
 */
public class Solution75 {
    public void sortColors(int[] nums) {
        int p0 = 0;
        int p2 = nums.length - 1;
        for (int i = 0; i <= p2; i++) {
            while (i<=p2 && nums[i] == 2) {
                int temp = nums[i];
                nums[i] = nums[p2];
                nums[p2] = temp;
                p2--;
            }
            if (nums[i]==0){
                int temp = nums[i];
                nums[i] =nums[p0];
                nums[p0] = temp;
                p0++;
            }
        }
    }

    public static void main(String[] args) {
        int[] nums = new int[]{1,1,2};
        new Solution75().sortColors(nums);
        System.out.println(Arrays.toString(nums));
    }
}